﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using FlickrSample.SL.Infrastructure;
using FlickrSample.SL.Infrastructure.Flickr.Entities;
using FlickrSample.View.User;
using GalaSoft.MvvmLight.Command;
using XamlingCore.Infrastructure.View;

namespace FlickrSample.View.Welcome
{
    public class WelcomeScreenViewModel : XContentViewModelBase
    {
        public RelayCommand AddUserCommand { get; set; }


        private FlickrUser currentUser;

        public override void OnInitialise()
        {
            Title = "welcome";
            init();
        }

        void init()
        {
            AddUserCommand = new RelayCommand(doAddUser);
        }

        private void doAddUser()
        {
            var model = CreateContentModel<UserSearchViewModel>((p) =>
                                                                    {
                                                                        p.UserAddedCallback = onUserAdded;
                                                                    });
            NavigateTo(model);
        }

        private void onUserAdded(FlickrUser obj)
        {
            CurrentUser = obj;
            
            var model = CreateContentModel<UserDetailViewModel>((userModel) =>
                                                                    {
                                                                        userModel.User = obj;
                                                                    });
            
            NavigateTo(model);
        }

        public FlickrUser CurrentUser
        {
            get { return currentUser; }
            set
            {
                currentUser = value;
                OnPropertyChanged("CurrentUser");
            }
        }

    }
}
